package com.example.maze.swing;

import com.example.maze.model.Coordinate;

/**
 * 寻路步骤信息类，记录每一步的操作
 * 
 * @author maze-demo
 */
public class SolverStep {
    
    public enum StepType {
        VISIT,      // 访问节点
        BACKTRACK,  // 回溯
        SOLUTION,   // 找到解路径上的节点
        START,      // 开始寻路
        END         // 结束寻路
    }
    
    private final StepType type;
    private final Coordinate coordinate;
    private final String description;
    private final long timestamp;
    
    public SolverStep(StepType type, Coordinate coordinate, String description) {
        this.type = type;
        this.coordinate = coordinate;
        this.description = description;
        this.timestamp = System.currentTimeMillis();
    }
    
    public static SolverStep visit(Coordinate coord, String description) {
        return new SolverStep(StepType.VISIT, coord, description);
    }
    
    public static SolverStep backtrack(Coordinate coord, String description) {
        return new SolverStep(StepType.BACKTRACK, coord, description);
    }
    
    public static SolverStep solution(Coordinate coord, String description) {
        return new SolverStep(StepType.SOLUTION, coord, description);
    }
    
    public static SolverStep start(String description) {
        return new SolverStep(StepType.START, null, description);
    }
    
    public static SolverStep end(String description) {
        return new SolverStep(StepType.END, null, description);
    }
    
    // Getters
    public StepType getType() {
        return type;
    }
    
    public Coordinate getCoordinate() {
        return coordinate;
    }
    
    public String getDescription() {
        return description;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    @Override
    public String toString() {
        if (coordinate != null) {
            return String.format("%s: %s at %s", type, description, coordinate);
        } else {
            return String.format("%s: %s", type, description);
        }
    }
}